package com.spring.controller.config;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class CommonPropertyPlaceholderConfigurer extends
		PropertyPlaceholderConfigurer {

	private Map<String, Object> ctxPropertiesMap = new HashMap<String, Object>();

	@Override
	protected void processProperties(
			ConfigurableListableBeanFactory beanFactoryToProcess,
			Properties props) throws BeansException {
		super.processProperties(beanFactoryToProcess, props);
		for (Object key : props.keySet()) {
			String keyStr = key.toString();
			String value = props.getProperty(keyStr);
			ctxPropertiesMap.put(keyStr, value);
		}
	}

	/**
	 * 根据属性名获取属性值
	 * 
	 * @param name
	 * @return Object
	 */
	public Object getContextProperty(String name) {
		return ctxPropertiesMap.get(name);
	}

	/**
	 * 获得所有属性名
	 * 
	 * @Author: bruce
	 * @param @return
	 * @return Set<String>
	 * @throws
	 */
	public Set<String> getContextPropertyKey() {
		return ctxPropertiesMap.keySet();
	}

}
